package com.bnq.control.common.utils;

import android.content.Context;
import android.widget.Toast;

public class ToastUtils {
    /**
     * 单例吐司
     */
    private static Toast toast;

    public static void showSingleToast(int toastID, Context context) {
        if (null == toast) {
            toast = Toast.makeText(context, context.getResources().getText(toastID), Toast.LENGTH_SHORT);
        } else {
            toast.cancel();
            toast = Toast.makeText(context, context.getResources().getText(toastID), Toast.LENGTH_SHORT);
        }
        toast.show();
    }

    public static void showSingleToast(String str, Context context) {
        if (null == toast) {
            toast = Toast.makeText(context, str, Toast.LENGTH_SHORT);
        } else {
            toast.cancel();
            toast = Toast.makeText(context, str, Toast.LENGTH_SHORT);
        }
        toast.show();
    }

    public static void showLongSingleToast(int toastID, Context context) {
        if (null == context) return;
        if (null == toast) {
            toast = Toast.makeText(context, context.getResources().getText(toastID), Toast.LENGTH_LONG);
        } else {
            toast.cancel();
            toast = Toast.makeText(context, context.getResources().getText(toastID), Toast.LENGTH_LONG);
        }
        toast.show();
    }
}
